"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/7/7 9:28
@Description : 

问题:  web服务器是否知道发起http请求的方式
1.  浏览器
       'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36'
2.  程序
       'User-Agent':'python-requests/2.32.3'

向   www.httpbin.org/get     请求   ->  响应   User-Agent
"""

import requests

url = 'http://www.httpbin.org/get'
response = requests.get(url)
"""
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Host": "www.httpbin.org", 
    "User-Agent": "python-requests/2.32.3", 
    "X-Amzn-Trace-Id": "Root=1-686b23a2-26d7f04e60e578a002d88698"
  }, 
  "origin": "36.159.235.4", 
  "url": "http://www.httpbin.org/get"
}
"""
print(response.text)

#  发送请求时 设置请求头信息   Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36',
    'Cookie': 'BIDUPSID=62C077A23D9D4F735023D25445E5DC2D; PSTM=1751849347'
}
response = requests.get(url, headers=headers)

"""
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Cookie": "BIDUPSID=62C077A23D9D4F735023D25445E5DC2D; PSTM=1751849347", 
    "Host": "www.httpbin.org", 
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36", 
    "X-Amzn-Trace-Id": "Root=1-686b2557-6690291c27108dad7047df78"
  }, 
  "origin": "36.159.235.4", 
  "url": "http://www.httpbin.org/get"
}


数字签名   网站的反扒技术  datasign
var datasign = 
$.md5('deviceid=' + deviceId + '&deviceos=' + deviceOs + '&devicetype=' 
+ deviceType + '&fontsize=' + fontsize + 
'&height=' + height + '&language=' 
+ weblang + '&length=' + length + 
'&productid=' + productId + '&softname=' +
 productName + '&softversion=' + productVersion + 
 '&timestamp=' + timestamp + '&width=' + width + 'hUuPd20171206LuOnD');


ip检测    代理ip  购买ip  


"""
print(response.text)

#  生成随机user-agent    列表   fake_useragent
from fake_useragent import UserAgent

random_user_agent = UserAgent().random
print(random_user_agent)
